
<template>
  <div class="planDetails" style="padding-bottom:50px;">
    <div>
       <img @click="onClickLeft" style="margin-top:5px" id="imgID" src="../../../assets/images/icon-arrow-right.png" alt="">
       <div style="font-size:16px;font-family:PingFang-SC-Medium;font-weight:500;color:rgba(51,51,51,1);margin-top:15px;">{{$route.query.virtualWalletName}} {{$route.query.lockedDays}}日抢先计划{{$route.query.productName}}</div>
    </div>
    <!-- 预期年化利率 -->
    <div class="profit">
      <div class="flex profit-list">
        <div class="profit-item">
          <div class="profit-icons">
            <div>{{$route.query.annualInterestRate}}%</div>
          </div>
          <div class="profit-text">预期年化利率</div>
        </div>
        <div class="profit-item">
          <div class="profit-icons">
            <div style="color:#333333">{{$route.query.lockedDays}}天</div>
          </div>
          <div class="profit-text">锁定期</div>
        </div>
      </div>
      <!-- 100%兑付 -->
      <div class="conversion">
        <div style="flex:1">100%兑付</div>
        <div>|</div>
        <div style="flex:1">账户安全保障</div>
        <div>|</div>
        <div style="flex:1">{{$route.query.minAmount}} {{$route.query.virtualWalletName}}起购</div>
      </div>
    </div>
    <div class="xian"></div>
    <!-- 申购倒计时 1天18小时20分钟 -->
    <div class="time">
      <div v-if="buySome" class="subscribe">申购倒计时{{$route.query.name}}天</div>
      <div v-if="buySome2" class="subscribe">申购已结束</div>
 
      <div style="display:flex;justify-content: center;margin-top:20px;" class="conversion">
        <div>
          <img src="../../../assets/images/icon-dot.png" alt>
        </div>
        <span style="color:#CBCBCB">————————</span>
        <div>
          <img src="../../../assets/images/icon-dot.png" alt>
        </div>
        <span style="color:#CBCBCB">————————</span>
        <div>
          <img src="../../../assets/images/icon-dot.png" alt>
        </div>
        <span style="color:#CBCBCB">————————</span>
        <div>
          <img src="../../../assets/images/icon-dot.png" alt>
        </div>
      </div>

      <!-- 认购开始 2019-04-30 14:00 -->
      <div class="subscription">
           <div>认购开始 {{begin}}</div>
           <div>起息日 {{value}}</div>
           <div>到期日 {{expire}}</div>
           <div>预期收款日 {{gathering}}</div>
      </div>
    </div>
    <div style="margin-top:20px;" class="xian"></div>

     <!-- 产品信息 -->
     <div class="product">
         <div>产品信息</div>
         <p></P>
         <ul style="text-align: left;">
             <li>产品类别 <span>固定收益</span></li>
             <li>产品总规模 <span style="margin-left:25px">1  {{$route.query.virtualWalletName}}</span></li>
             <li>收益方式 <span>一次性还本付息</span></li>
             <li>投资去向 <span>由本平台精选的量化套利投资组合</span></li>
             <li>固定期限理财，产品结束前不可退出</li>
         </ul>
     </div>
     <div style="margin-top:20px;" class="xian"></div>
     <!-- 常见问题 -->
    <div class="login-content">
     <section class="cent">
       <van-cell @click="security" title="安全保障" is-link></van-cell>
       <van-cell @click="common" title="常见问题" is-link></van-cell>
     </section>
    </div>
    <!-- <div style="margin-top:18px;">剩余可认购额度  0.29{{$route.query.virtualWalletName}}</div>     -->   
    <!-- 认购按钮 -->
    <div v-if="buyBtm" class="toBtm" @click="goBuy">认购</div>  

    <!-- 弹框身份认证 -->
    <div class="cover" v-if="flagCover">
      <div class="cover-contain">
        <p></p>
        <p>您还未设置身份认证，暂无法进行提币</p>
        <div class="submit">
          <button style="margin-top:0" type="submit" @click="personTo" class="submit-btn">身份认证</button>
        </div>
        <img @click="flagCover=false" id="close" src="../../../assets/images/close.png" alt="">
      </div>
    </div>

    <!-- 弹框交易密码认证 -->
    <div class="cover" v-if="flagCover2">
      <div class="cover-contain">
        <p></p>
        <p>您还未完成交易密码，暂无法进行提币</p>
        <div class="submit">
          <button style="margin-top:0" type="submit" class="submit-btn" @click="passTo">交易密码</button>
        </div>
        <img @click="flagCover2=false" id="close" src="../../../assets/images/close.png" alt="">
      </div>
    </div>



</div>  
</template>
<script>
import Vue from "vue";
import axios from "axios";
import { coinPlan, login } from "../../../axios/api.js";
import { NavBar, Toast, Icon, Cell,} from "vant";
export default {
  name:"planDetails",
  components: {
    [NavBar.name]: NavBar,
    [Toast.name]: Toast,
    [Icon.name]: Icon,
    [Cell.name]: Cell
  }, 
  data() {
    return {
      begin:"", //认购开始
      value:"", //起息日
      expire:"", //到期日
      gathering:"", //预期收款日
      data: {
        page: "1",
        rows: "6"
      },  
      flagCover:false,
      flagCover2:false,
      buySome:true,
      buySome2:true,
      time1:this.$route.query.name,
      time2:this.$route.query.name2,//最大天数
      buyBtm:true
    };
  },  
   created() {
    this.getTime();

    //判断是否可购买 
    if(this.time1 > this.time2 || this.time1 <= 0){
      this.buyBtm = false
      this.buySome = false
      this.buySome2 = true
    }else{
      this.buyBtm = true
      this.buySome = true
      this.buySome2 = false
    }
  }, 
  methods: {
    //返回上一页
    onClickLeft() {
      this.$router.go(-1);
    },    
    // 跳转安全问题页面
    security() {         
      this.$router.push("/security");
    },
    //常见问题跳转
    common() {         
      this.$router.push("/common");
    }, 
    personTo(){
      this.$router.push({name:'identityAuthentication'})
    },
    passTo(){
      this.$router.push({name:'buypassword'})
    },
    //时间获取
    getTime(){
      coinPlan({
      params: this.data     
    }).then(res => {
       this.begin = res.data.data.listCoinPlan[0].subscriptionStartTime,
       this.value = res.data.data.listCoinPlan[0].startInterestTime,
       this.expire = res.data.data.listCoinPlan[0].maturityTime,
       this.gathering = res.data.data.listCoinPlan[0].receiptTime,
       this.begin = this.begin.substring(0,this.begin.indexOf(" "))
       this.value = this.value.substring(0,this.value.indexOf(" "))
       this.expire = this.expire.substring(0,this.expire.indexOf(" "))
       this.gathering = this.gathering.substring(0,this.gathering.indexOf(" "))
       console.log(this.begin)
    });
    },
    //buy
    goBuy(){
      if(localStorage.getItem('tradePassword') == 1){
        this.flagCover2 = false
      }else{
        this.flagCover2 = true
        return false
      }
       if(!localStorage.getItem('cardId') || localStorage.getItem('cardId') == 'null' ){
          this.flagCover = true
          return false
        }else{
          this.flagCover = false
        }
        this.$router.push({
          name:'buy',
          query:{
            id:this.$route.query.id,
            name1:this.$route.query.minAmount,//认购数量
            name2:this.$route.query.annualInterestRate,//预期年化率
            name3:this.gathering,//预期收款日
            name4:this.$route.query.virtualWalletName,//购买的类型
            name5:this.$route.query.moreNum,//最大认购量
            name6:this.$route.query.lockedDays,//天数
            name7:this.$route.query.productName,
            name8:this.$route.query.prodId,
          }  
          })
    } 
  },
 
};
</script>


<style lang="less" scoped>
@import "../../../assets/less/variable.less";
.planDetails {
    width: 100%;
    height: 100vh;
    overflow-y:auto;
  background: #ffffff;

  #imgID{
    width: 14px;
    height: 14px;
    position: absolute;
    left: 20px;
    // margin-top: 15px;
  }
  .profit {
    // width: 100%;
    margin: 10px 0;
    .profit-title {
      padding: 10px 0;
      font-size: @base_textSize;
      color: @base_textColor;
    }
    .profit-list {
      padding: 10px 0;
      .profit-item {
        width: 50%;
        .profit-icons {
          font-size: 2em;
          color: #d1a658;
        }
        .profit-text {
          font-size: 14px;
          font-family: PingFang-SC-Regular;
          font-weight: 400;
          color: rgba(102, 102, 102, 1);
          margin-top: 15px;
        }
      }
    }
    // 兑换
    .conversion {
      display: flex;
    }
    .conversion div {
      font-size: 12px;
      font-family: PingFang-SC-Regular;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      margin-top: 26px;
    }
  }
  .xian {
    width: 100%;
    height: 10px;
    background: #f6f6f8;
  }
  .time {
    padding: 10px 0;
  }
  .time .subscribe {
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    color: rgba(209, 166, 88, 1);
    text-align: left;
    margin-left: 25px;
  }
  .time img {
    width: 8px;
    height: 8px;
  }
//   认购开始
 .subscription{
     width: 100%;
     display: flex;
     justify-content:space-around;
 }
 .subscription>div{
     width:70px;
    height:35px;
    font-size:11px;
    font-family:PingFang-SC-Regular;
    font-weight:400;
    color:rgba(51,51,51,1);
    margin-top: 10px;

 }
//  产品信息
 .product>div{
     font-size:16px;
    font-family:PingFang-SC-Medium;
    font-weight:500;
    color:rgba(51,51,51,1);
    margin-left: 25px;
    text-align: left;
    margin-top: 17px;
   
   
 }
 .product P{
      border-bottom: 1px solid #EFEFEF;
      margin-top: 17px;
 }
 ul li{
     font-size:14px;
    font-family:PingFang-SC-Medium;
    font-weight:500;
    color:rgba(153,153,153,1);
    line-height: 16px;
    margin-left: 25px;
    margin-top: 8px;
 }
 ul li span{
   color: #333333;
   margin-left: 40px;
 }
}

//认购
.toBtm{
  width: 100%;
  height: 40px;
  font-size: 18px;
  line-height: 40px;
  color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 99;
  background-color:#d5aa6e; 
}

.cover {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 99;
  font-size: 14px;
  .cover-contain {
    width: 90%;
    background-color: #fff;
    border-radius: 5px;
    margin: 30vh auto;
    padding: 40px 20px 20px;
    box-sizing: border-box;
    position: relative;
    #close{
        position: absolute;
        right: 0;
        top:0;
        width: 10%;
    }
  }
}
.detail{
    width: 90%;
    margin: 30px auto;
    text-align: left;
    font-size: 9px;
    color: #999;
    p:first-child{
        font-size: 12px;
    }
}

.submit {
  margin-top: 0.67rem;
  width: 100%;
  background-color: #fff;
  color: #fff;
  font-size: 14px;
  .submit-btn {
    width: 85%;
    height: 34px;
    text-align: center;
    line-height: 34px;
    font-size: 14px;
    background-color: #d6ab6f;
    color: white;
    border-radius: 20px;
    margin: 10vh auto 0;
    border: 0;
  }
}
</style>

